from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-09 14:02:31.222887
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 09, Jul, 2022
Time: 14:02:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7396
Nobs: 712.000 HQIC: -50.0940
Log likelihood: 8910.32 FPE: 1.40469e-22
AIC: -50.3171 Det(Omega_mle): 1.23899e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298478 0.057366 5.203 0.000
L1.Burgenland 0.104534 0.037657 2.776 0.006
L1.Kärnten -0.109455 0.019965 -5.482 0.000
L1.Niederösterreich 0.210483 0.078742 2.673 0.008
L1.Oberösterreich 0.105666 0.077038 1.372 0.170
L1.Salzburg 0.257027 0.040310 6.376 0.000
L1.Steiermark 0.044647 0.052498 0.850 0.395
L1.Tirol 0.109662 0.042625 2.573 0.010
L1.Vorarlberg -0.061073 0.036861 -1.657 0.098
L1.Wien 0.045419 0.068002 0.668 0.504
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047786 0.120074 0.398 0.691
L1.Burgenland -0.034211 0.078820 -0.434 0.664
L1.Kärnten 0.041220 0.041789 0.986 0.324
L1.Niederösterreich -0.167572 0.164816 -1.017 0.309
L1.Oberösterreich 0.422566 0.161250 2.621 0.009
L1.Salzburg 0.288343 0.084373 3.417 0.001
L1.Steiermark 0.100711 0.109884 0.917 0.359
L1.Tirol 0.318638 0.089218 3.571 0.000
L1.Vorarlberg 0.027319 0.077154 0.354 0.723
L1.Wien -0.037464 0.142335 -0.263 0.792
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187841 0.029346 6.401 0.000
L1.Burgenland 0.089359 0.019264 4.639 0.000
L1.Kärnten -0.007952 0.010213 -0.779 0.436
L1.Niederösterreich 0.265095 0.040281 6.581 0.000
L1.Oberösterreich 0.137893 0.039410 3.499 0.000
L1.Salzburg 0.045994 0.020621 2.230 0.026
L1.Steiermark 0.019873 0.026856 0.740 0.459
L1.Tirol 0.091427 0.021805 4.193 0.000
L1.Vorarlberg 0.057273 0.018857 3.037 0.002
L1.Wien 0.114407 0.034787 3.289 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111766 0.029846 3.745 0.000
L1.Burgenland 0.045155 0.019592 2.305 0.021
L1.Kärnten -0.013770 0.010387 -1.326 0.185
L1.Niederösterreich 0.191470 0.040967 4.674 0.000
L1.Oberösterreich 0.303303 0.040081 7.567 0.000
L1.Salzburg 0.108337 0.020972 5.166 0.000
L1.Steiermark 0.104661 0.027313 3.832 0.000
L1.Tirol 0.104073 0.022176 4.693 0.000
L1.Vorarlberg 0.066606 0.019178 3.473 0.001
L1.Wien -0.022216 0.035379 -0.628 0.530
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134462 0.054436 2.470 0.014
L1.Burgenland -0.051992 0.035733 -1.455 0.146
L1.Kärnten -0.044333 0.018945 -2.340 0.019
L1.Niederösterreich 0.156351 0.074721 2.092 0.036
L1.Oberösterreich 0.139570 0.073104 1.909 0.056
L1.Salzburg 0.286814 0.038251 7.498 0.000
L1.Steiermark 0.047623 0.049816 0.956 0.339
L1.Tirol 0.167105 0.040448 4.131 0.000
L1.Vorarlberg 0.092040 0.034978 2.631 0.009
L1.Wien 0.074692 0.064528 1.158 0.247
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055126 0.043302 1.273 0.203
L1.Burgenland 0.037956 0.028424 1.335 0.182
L1.Kärnten 0.050958 0.015070 3.381 0.001
L1.Niederösterreich 0.217507 0.059437 3.659 0.000
L1.Oberösterreich 0.295188 0.058151 5.076 0.000
L1.Salzburg 0.048007 0.030427 1.578 0.115
L1.Steiermark 0.001378 0.039627 0.035 0.972
L1.Tirol 0.141330 0.032174 4.393 0.000
L1.Vorarlberg 0.072669 0.027824 2.612 0.009
L1.Wien 0.080794 0.051330 1.574 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174918 0.051780 3.378 0.001
L1.Burgenland -0.002954 0.033990 -0.087 0.931
L1.Kärnten -0.062965 0.018021 -3.494 0.000
L1.Niederösterreich -0.081005 0.071075 -1.140 0.254
L1.Oberösterreich 0.194236 0.069537 2.793 0.005
L1.Salzburg 0.056671 0.036385 1.558 0.119
L1.Steiermark 0.235781 0.047386 4.976 0.000
L1.Tirol 0.497581 0.038474 12.933 0.000
L1.Vorarlberg 0.043489 0.033272 1.307 0.191
L1.Wien -0.053208 0.061380 -0.867 0.386
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170587 0.059097 2.887 0.004
L1.Burgenland -0.010476 0.038792 -0.270 0.787
L1.Kärnten 0.063633 0.020567 3.094 0.002
L1.Niederösterreich 0.207247 0.081117 2.555 0.011
L1.Oberösterreich -0.075184 0.079362 -0.947 0.343
L1.Salzburg 0.213140 0.041526 5.133 0.000
L1.Steiermark 0.125479 0.054081 2.320 0.020
L1.Tirol 0.068770 0.043910 1.566 0.117
L1.Vorarlberg 0.118370 0.037973 3.117 0.002
L1.Wien 0.120898 0.070053 1.726 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362591 0.034221 10.595 0.000
L1.Burgenland 0.006295 0.022464 0.280 0.779
L1.Kärnten -0.023487 0.011910 -1.972 0.049
L1.Niederösterreich 0.216964 0.046973 4.619 0.000
L1.Oberösterreich 0.202463 0.045957 4.406 0.000
L1.Salzburg 0.043168 0.024047 1.795 0.073
L1.Steiermark -0.014961 0.031317 -0.478 0.633
L1.Tirol 0.104936 0.025427 4.127 0.000
L1.Vorarlberg 0.069936 0.021989 3.180 0.001
L1.Wien 0.034261 0.040566 0.845 0.398
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037484 0.139066 0.194775 0.155987 0.115258 0.102853 0.057529 0.217509
Kärnten 0.037484 1.000000 -0.015607 0.134111 0.056015 0.094999 0.435670 -0.053565 0.093663
Niederösterreich 0.139066 -0.015607 1.000000 0.334875 0.141119 0.293395 0.092329 0.175400 0.312965
Oberösterreich 0.194775 0.134111 0.334875 1.000000 0.227172 0.325056 0.176458 0.164345 0.262029
Salzburg 0.155987 0.056015 0.141119 0.227172 1.000000 0.138037 0.116876 0.138337 0.129283
Steiermark 0.115258 0.094999 0.293395 0.325056 0.138037 1.000000 0.145232 0.131565 0.070602
Tirol 0.102853 0.435670 0.092329 0.176458 0.116876 0.145232 1.000000 0.110682 0.142373
Vorarlberg 0.057529 -0.053565 0.175400 0.164345 0.138337 0.131565 0.110682 1.000000 -0.001681
Wien 0.217509 0.093663 0.312965 0.262029 0.129283 0.070602 0.142373 -0.001681 1.000000